package com.lh.blogConsumer.service.Impl;

import com.lh.blogCommon.util.PageUtils;
import com.lh.blogCommon.util.Query;
import com.lh.blogConsumer.entity.PersonalSkillsEntity;
import com.lh.blogConsumer.entity.ProjectSkillsEntity;
import com.lh.blogConsumer.feign.OssFeignService;
import com.lh.blogConsumer.mapper.PersonalSkillsMapper;
import com.lh.blogConsumer.service.PersonalSkillsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;


@Service("personalSkillsService")
public class PersonalSkillsServiceImpl extends ServiceImpl<PersonalSkillsMapper, PersonalSkillsEntity> implements PersonalSkillsService {

    @Autowired
    OssFeignService ossFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<PersonalSkillsEntity> queryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");
        System.out.println(params);
        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("skills_id",key).or()
                    .eq("skills_name",key).or()
                    .eq("skills_synopsis", key).or()
                    .eq("proficiency", key).or()
                    .eq("start_learn", key).or()
                    .eq("end_learn", key);
        }
        queryWrapper.orderByDesc("skills_id");

        IPage<PersonalSkillsEntity> page = this.page(
                new Query<PersonalSkillsEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void removeAdImageByIds(String[] skillsIds) {
        List<String> imgs = baseMapper.selectBatchIds(Arrays.asList(skillsIds)).stream().map((item) -> {
            return item.getSkillsImg();
        }).collect(Collectors.toList());
        ossFeignService.removeList(imgs);
    }

}